package com.zdgk.core.web.controller.read;

import com.zdgk.core.control.read.modbus.ModbusMasterConfig;
import com.zdgk.core.control.read.modbus.cache.DeviceRegisterCacheResult;
import com.zdgk.core.web.common.CommonResult;
import com.zdgk.core.web.controller.read.entity.ModbusStatusEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class ModbusController {

    @Resource
    private ModbusMasterConfig modbusMasterConfig;

    /**
     * modbus主站状态
     * @return
     */
    @GetMapping("/modbus/status")
    public CommonResult<?> modbusStatus(){
        ModbusStatusEntity modbusStatusEntity = new ModbusStatusEntity();
        modbusStatusEntity.setIsConnected(modbusMasterConfig.isConnected());
        modbusStatusEntity.setLastTime(DeviceRegisterCacheResult.lastTime);
        return CommonResult.data(modbusStatusEntity);
    }

}
